//<string> ==> 具体的某种类型：字符串类型
//Array    ==> 是一个interface
//Array    ==> interface Array<T> {}
//其实string 就是 上面Array<T> ==> 其实就是T
let arr1:Array<number> = [1,2,3];
let arr2:Array<string> = ['a','b','c'];

//函数泛型
function fun1<T>( arg:T): T {
    return arg;
}

fun1<string>('你好');
fun1<number>(123);

//可以定义多个泛型
function fun2<T,U>( a:T,b:U){

}
fun2<number,string>(1,'2');


//来看一个需求，说这个泛型，需要有length属性
function fun3<T extends String | string[] | number[]>( arg:T ): number {
    
    return arg.length;

}

fun3<string>('你好');
fun3<string[]>(['a','b']);
fun3<number[]>([1,2,3]);


//泛型接口
interface IArg{
    length:number;
}
function fun4<T extends IArg>( arg:T): number {
    return arg.length;
}
fun4<string>('你好');
fun4<string[]>(['a','b']);
fun4<number[]>([1,2,3]);


interface Idata<T>{
    a:T;
    b:T;
    c:string;
}

let data:Idata<number> = {
    a:1,
    b:2,
    c:'aaaa'
}


//class类的泛型

class Person<T,U>{
    userName:T;
    userage:U;
    constructor( name:T, age:U ){
        this.userName = name;
        this.userage = age;
    }
}

let p1 = new Person<string,number>('你好',28);